﻿using System;
using System.ComponentModel;

namespace SBPweb.Communication.Shared.Library.Contacts
{
    
    public abstract class ContactBase : IContact
    {

        #region Protected fields

        protected string id;
        protected string displayName;
        protected ContactPresenceStateBase presenceState;

        #endregion

        #region Constructor logic

        public ContactBase(string id)
        {
            this.id = id;
            this.displayName = id.Substring(0, id.IndexOf('@'));
        }

        public ContactBase(string id, string displayName)
            : this(id)
        {
            this.displayName = displayName;
            this.presenceState = new ContactPresenceStateBase(null);
        }

        #endregion

        #region Property accessors

        public string Id
        {
            get
            {
                return id;
            }
        }

        public string DisplayName
        {
            get
            {
                return displayName;
            }
            protected set
            {
                displayName = value;
            }
        }

        public virtual ContactPresenceStateBase PresenceState
        {
            get
            {
                return presenceState;
            }
            protected set
            {
                presenceState = value;
            }
        }

        #endregion

        #region Events

        #endregion

        #region Methods

        public override bool Equals(object obj)
        {
            ContactBase o = obj as ContactBase;
            if (o == null)
            {
                return false;
            }
            return Id.Equals(o.Id);
        }

        public override int GetHashCode()
        {
            return Id.GetHashCode();
        }

        public override string ToString()
        {
            return string.Format("{0} ({1})", DisplayName, Id);
        }

        #endregion

    }

}